<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.bluesky.light.user.*"%>
<%
request.setCharacterEncoding("utf-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<% 

String action = request.getParameter("action");

if (action != null && action.trim().equals("register")) {
	String username = request.getParameter("username");
	String pwd = request.getParameter("pwd");
	String name = request.getParameter("name");
	String idcard = request.getParameter("idcard");
	String sex = request.getParameter("sex");
	String birth_year = request.getParameter("birth_year");
	String birth_month = request.getParameter("birth_month");
	String birth_day = request.getParameter("birth_day");
	String phone = request.getParameter("phone");
	String addr = request.getParameter("addr");
	
	Calendar cal = Calendar.getInstance();
	cal.clear();
	cal.set(Integer.parseInt(birth_year), (Integer.parseInt(birth_month)-1), Integer.parseInt(birth_day));
	Date birth = cal.getTime();
	
	User u = new User();	
	u.setUsername(username);
	u.setPwd(pwd);
	u.setName(name);
	u.setIdcard(idcard);
	u.setSex(sex);
	u.setBirth(birth);
	u.setPhone(phone);
	u.setAddr(addr);
	u.setRdate(new Date());
	UserService.getInstance().save(u);	
	response.sendRedirect("user_add.jsp?from=" + basePath);
	return;
}

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>light - register</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="css/main.css" rel="stylesheet" type="text/css" />
	
		<script language=JavaScript  src="js/checklist.js" type = "text/javascript"> 
	</script>
	
  </head>
  
  <body onload = "checkAge(register.birth_year.value,register.birth_month.value)">
	<!-- header -->
	<div id="header">
		<div id="logo"><img src="images/logo_small2.png"/></div>
	</div>
	<!-- // header -->
	<!-- nav -->
	<div id="nav">
	</div>
	<!-- // nav -->
	<!-- container -->
	<div id="container">
		<!-- contents -->
		<div id="contents">
			<div id="regist_form">
	        	<form method="post" name="register" action="user_addInput.jsp" onSubmit="return checkdata()">
	        		<input type="hidden" name="action" value="register"/>
	            	<h2>Beginning to use</h2>
	            	<table>	            		
	                	<tr><td>User Name: </td><td><input name="username" type="text" onblur = "checkUserName(this.value)"/>
	                	<span id = "usernameErr"></span><br></td></tr>
	                    <tr><td>Password: </td><td><input name="pwd" type="password" onblur = "checkPassWord(this.value)"/>
	                    <span id = "passwordErr"></span><br></td></tr>
	                    <tr><td>Confirm Password: </td><td><input name="pwd2" type="password" onblur = "checkPassWord2(this.value)"/>
	                    <span id = "password2Err"></span><br></td></tr>
	                    <tr><td>Name: </td><td><input name="name" type="text" onblur = "checkName(this.value)"/>
	                    <span id = "nameErr"></span><br></td></tr>
	                    <tr><td>ID Card: </td><td><input name="idcard" type="text" onblur = "checkid(this.value)"/>
	                    <span id = "idErr"></span><br></td></tr>
	                    <tr><td>Sex: </td>
	                    <td>
	                    	<select name = "sex">
	                    		<option value="M">Male</option>
	                    		<option value="F">Female</option>
	                    	</select>
	                    <tr>
	                    	<td>Birth: </td>
	                    	<!-- <td><input name="year" type="text" onblur = "checkAge(this.value)"/>
	                    	<span id = "birthErr"></span><br></td> -->
		                    <td>
		                    	<select name = "birth_year" onchange = "checkAge(register.birth_year.value,register.birth_month.value)">
		                    		<option value="1990">1990</option>
		                    		<option value="1991">1991</option>
		                    		<option value="1992">1992</option>
		                    		<option value="1993">1993</option>
		                    		<option value="1994">1994</option>
		                    		<option value="1995">1995</option>
		                    		<option value="1996">1996</option>
		                    		<option value="1997">1997</option>
		                    		<option value="1998">1998</option>
		                    		<option value="1999">1999</option>
		                    	</select>
		                    	<select name = "birth_month" onchange = "checkAge(register.birth_year.value,register.birth_month.value)">
		                    		<option value="1">1</option>
		                    		<option value="2">2</option>
		                    		<option value="3">3</option>
		                    		<option value="4">4</option>
		                    		<option value="5">5</option>
		                    		<option value="6">6</option>
		                    		<option value="7">7</option>
		                    		<option value="8">8</option>
		                    		<option value="9">9</option>
		                    		<option value="10">10</option>
		                    		<option value="11">11</option>
		                    		<option value="12">12</option>
		                    	</select>
		                    	<select name = "birth_day" >
		                    		
		                    		<option value="1">1</option>
		                    		<option value="2">2</option>
		                    		<option value="3">3</option>
		                    		<option value="4">4</option>
		                    		<option value="5">5</option>
		                    		<option value="6">6</option>
		                    		<option value="7">7</option>
		                    		<option value="8">8</option>
		                    		<option value="9">9</option>
		                    		<option value="10">10</option>
		                    		<option value="11">11</option>
		                    		<option value="12">12</option>
		                    		<option value="13">13</option>
		                    		<option value="14">14</option>
		                    		<option value="15">15</option>
		                    		<option value="16">16</option>
		                    		<option value="17">17</option>
		                    		<option value="18">18</option>
		                    		<option value="19">19</option>
		                    		<option value="20">20</option>
		                    		<option value="21">21</option>
		                    		<option value="22">22</option>
		                    		<option value="23">23</option>
		                    		<option value="24">24</option>
		                    		<option value="25">25</option>
		                    		<option value="26">26</option>
		                    		<option value="27">27</option>
		                    		<option value="28">28</option>
		                    	</select>
		                    	<!--<span id = "birthErr"></span><br> -->
		                    </td>
	                    </tr>
	                    <tr><td>Phone: </td>
		                    <td><input name="phone" type="text" onblur = "checkphone(this.value)"/>
		                    <span id = "phoneErr"></span><br>
		                    </td>
	                    </tr>
	                    <tr><td>Address: </td><td><input name="addr" type="text" onblur = "checkaddress(this.value)"/>
	                    <span id = "addressErr"></span><br></td></tr>
	                    <tr><td/><td/></tr>                  
	                </table>
	                <center><input name="regsubmit" type="submit" value="OK! Create a new acount!"/></center>
	            </form>
	        </div>
	    </div>
	    <!-- // contents -->
	</div>
	<!-- // container -->
	<div id="footer">
		<div id="bs_stdio">
	    	©2011-2011 www.bluesky.com.mo All Rights Reserved<br/>
	    	<img src="images/bluesky_logo.png" />
	    </div>
	</div>
  </body>
</html>
